package org.gem.example;

import org.gem.example.product.Apple;
import org.gem.example.product.Mango;
import org.gem.example.product.Strawberry;
import org.gem.example.sale.ShoppingCart;
import org.gem.example.sale.ShoppingItem;
import org.gem.example.strategy.FullReduction;
import org.gem.example.strategy.TwentyPercentOff;

import java.math.BigDecimal;

public class Main {

    public static void main(String[] args) {
        // 测试顾客A: 苹果+草莓 预期计算: 2*8 + 3*13 = 16+39=55
        SaleForA(2, 3, 55);
        SaleForA(0, 0, 33);

        // 测试顾客B: 苹果+草莓+芒果 预期计算: 2*8 + 3*13 + 20*1= 16+39+20=75
        SaleForB(2, 3, 1, 75);
        SaleForB(0, 0, 0, 0);

        // 测试顾客C: 苹果+草莓(8折)+芒果 预期计算: 2*8 + 3*13*0.8 + 4*20 = 16+31.2+80=127.2
        SaleForC(2, 3, 4, 127.2);
        SaleForC(0, 0, 0, 0);

        // 测试顾客D: 苹果+草莓+芒果，满100减10 总价: 5*(8+13+20)=205，满减后205-10=195
        SaleForD(5,5,5,195);
        // 测试顾客D: 苹果+草莓+芒果，满100减10 总价: 8+13+20=41，不满足100，结果还是41
        SaleForD(1,1,1,41);
        SaleForD(0,0,0,0);
    }

    private static void SaleForA(double appleQ, double strawberryQ, double expect) {
        ShoppingCart cart = new ShoppingCart();
        cart.addItem(new ShoppingItem(new Apple(), appleQ));
        cart.addItem(new ShoppingItem(new Strawberry(), strawberryQ));

        Validation.validateCalculation(cart, new BigDecimal(expect));
    }

    private static void SaleForB(int appleQ, int strawberryQ, int mangoQ, double expect) {
        ShoppingCart cart = new ShoppingCart();
        cart.addItem(new ShoppingItem(new Apple(), appleQ));
        cart.addItem(new ShoppingItem(new Strawberry(), strawberryQ));
        cart.addItem(new ShoppingItem(new Mango(), mangoQ));

        Validation.validateCalculation(cart, new BigDecimal(expect));
    }

    private static void SaleForC(int appleQ, int strawberryQ, int mangoQ, double expect) {
        ShoppingCart cart = new ShoppingCart();
        cart.addItem(new ShoppingItem(new Apple(), appleQ));
        cart.addItem(new ShoppingItem(new Strawberry(), strawberryQ, new TwentyPercentOff()));
        cart.addItem(new ShoppingItem(new Mango(), mangoQ));

        Validation.validateCalculation(cart, new BigDecimal(expect));
    }

    private static void SaleForD(int appleQ, int strawberryQ, int mangoQ, double expect) {
        ShoppingCart cart1 = new ShoppingCart();
        cart1.addItem(new ShoppingItem(new Apple(), appleQ));
        cart1.addItem(new ShoppingItem(new Strawberry(), strawberryQ));
        cart1.addItem(new ShoppingItem(new Mango(), mangoQ));
        cart1.setDiscountStrategy(new FullReduction(100, 10));

        Validation.validateCalculation(cart1, new BigDecimal(expect));
    }

}